//
//  Emitter.swift
//  HisPaste
//
//  Created by 烟雀 on 2024/2/15.
//

import Foundation

class Emitter<T>{
    
    private var _eventDeque: [Event_<T>] = []
    // private let _eventHandler: Event_<T>? = nil
    
    private func addToDeque(listenr: @escaping Event_<T>){
        if !self._eventDeque.contains(where: {
            _event in
            
            // 比较地址以检查闭包是否相同
            return _event as AnyObject === listenr as AnyObject
        }){
            self._eventDeque.append(listenr)
        }
    }
    
    func event() -> Event<T>{
        return self.addToDeque
    }
    
    func fire(args: T?){
        for oneEve in _eventDeque {
            oneEve(args)
        }
    }
    
}


